﻿using System.Data.Entity;
using ExcellentCRM.DataService.Models;

namespace ExcellentCRM.DataService
{
    public class DataServiceContext : DbContext
    {
        public static string DefaultConnName = "DefaultConnection";
        public DataServiceContext() : base(DefaultConnName)
        {
        }

        public DataServiceContext(string connName) : base(connName)
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Staff>()
                        .HasMany(p => p.Reminds)
                        .WithRequired(p => p.RemindTarget)
                        .WillCascadeOnDelete(false);
            modelBuilder.Entity<ContactRecord>()
                        .HasRequired(p => p.Consultant)
                        .WithMany(p => p.ContactRecords)
                        .WillCascadeOnDelete(false);
        }

        public DbSet<Account> Accounts { get; set; }

        public DbSet<Role> Roles { get; set; }

        public DbSet<AccountRole> AccountRoles { get; set; }

        public DbSet<Menu> Menus { get; set; }

        public DbSet<RoleMenu> RoleMenus { get; set; }

        public DbSet<Department> Departments { get; set; }

        public DbSet<Staff> Staff { get; set; }

        public DbSet<EnterpriseClient> EnterpriseClients { get; set; }

        public DbSet<StuClient> StuClients { get; set; }

        public DbSet<CostInfo> CostInfos { get; set; }

        public DbSet<Course> Courses { get; set; }

        public DbSet<StuCourse> StuCourses { get; set; }

        public DbSet<ContactRecord> ContactRecords { get; set; }

        public DbSet<Grade> Grades { get; set; }

        public DbSet<Group> Groups { get; set; }

        public DbSet<Remind> Reminds { get; set; }

        public DbSet<Schedule> Schedules { get; set; }

        public DbSet<Teacher> Teachers { get; set; }

        public DbSet<AttendanceRecord> AttendanceRecords { get; set; }

        public DbSet<TestResult> TestResults { get; set; }

        public DbSet<MembershipCard> MembershipCards { get; set; }

        public DbSet<MbsCardRecord> MembershipCardRecords { get; set; }
    }
}